package demo;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * Creared with IntelliJ IDEA.
 * Description:
 * User:yxd
 * Date:2022-03-18
 * Time:17:58
 */
public class TestCreate {
    public static void main(String[] args) throws SQLException {
        //数据源
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/school?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("123456");
        //连接
        Connection connection = dataSource.getConnection();
        //sql语句
        String sql = "create table student(id int,name varchar(40))";
        //转换为对象
        PreparedStatement statement = connection.prepareStatement(sql);


        //执行
        System.out.println(statement.executeUpdate());
        //回收资源
        statement.close();
        connection.close();
    }


}
